//
//  OneOfShopsViewController.m
//  project_delicious
//
//  Created by 章历杰 on 15/3/25.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "OneOfShopsViewController.h"
#import "AFNetworking.h"
#import "UIColor+AddColor.h"
#import "MBProgressHUD.h"
@interface OneOfShopsViewController ()
@property (nonatomic, retain) NSMutableDictionary *mDic;
@property (nonatomic, retain) MBProgressHUD *HUD;
@end

@implementation OneOfShopsViewController
- (void)dealloc
{
    [_num release];
    [_mDic release];
    [_HUD release];
    [super dealloc];
}
//解析数据
- (void)startAnalyze:(NSString *)str
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.mDic = [[responseObject objectForKey:@"data"] objectForKey:@"shop_detail_item"];
        //店铺详情
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-60, 80, 120, 50)];
        title.text = @"店铺详情";
        title.textAlignment = NSTextAlignmentCenter;
        title.layer.borderWidth = 1;
        title.layer.cornerRadius = 10;
        title.layer.borderColor = [[UIColor colorFromHexCode:@"#56abe4"] CGColor];
        [self.view addSubview:title];
        [title release];
        //店铺图片
        UIImageView *shopPic = [[UIImageView alloc] initWithFrame:CGRectMake(10, 150, 20, 20)];
        shopPic.image = [UIImage imageNamed:@"oneOfShop.png"];
        shopPic.layer.masksToBounds = YES;
        [self.view addSubview:shopPic];
        [shopPic release];
        //店名
        UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(35, 135, self.view.frame.size.width-70, 50)];
        name.text = [self.mDic objectForKey:@"name"];
        name.font = [UIFont systemFontOfSize:14];
        name.layer.borderColor = [[UIColor colorFromHexCode:@"#56abe4"] CGColor];
        name.layer.borderWidth = 1;
        name.layer.cornerRadius = 10;
        name.numberOfLines = 0;
        [self.view addSubview:name];
        [name release];
        //位置图片
        UIImageView *location = [[UIImageView alloc] initWithFrame:CGRectMake(10, 203, 20, 20)];
        location.image = [UIImage imageNamed:@"HOTSHOP_lp.png"];
        location.layer.masksToBounds = YES;
        [self.view addSubview:location];
        [location release];
        //地址
        UILabel *shopLoca = [[UILabel alloc] initWithFrame:CGRectMake(35, 190, self.view.frame.size.width-70, 50)];
        shopLoca.text = [self.mDic objectForKey:@"address"];
        shopLoca.font = [UIFont systemFontOfSize:14];
        shopLoca.layer.borderColor = [[UIColor colorFromHexCode:@"#56abe4"] CGColor];
        shopLoca.layer.borderWidth = 1;
        shopLoca.layer.cornerRadius = 10;
        shopLoca.numberOfLines = 0;
        [self.view addSubview:shopLoca];
        [shopLoca release];
        //电话图片
        UIImageView *tele = [[UIImageView alloc] initWithFrame:CGRectMake(10, 258, 20, 20)];
        tele.image = [UIImage imageNamed:@"telephone.png"];
        tele.layer.masksToBounds = YES;
        [self.view addSubview:tele];
        [tele release];
        //电话
        UILabel *teleNum = [[UILabel alloc] initWithFrame:CGRectMake(35, 245, self.view.frame.size.width-70, 50)];
        teleNum.text = [self.mDic objectForKey:@"phone"];
        teleNum.font = [UIFont systemFontOfSize:14];
        teleNum.layer.borderColor = [[UIColor colorFromHexCode:@"#56abe4"] CGColor];
        teleNum.layer.borderWidth = 1;
        teleNum.layer.cornerRadius = 10;
        teleNum.numberOfLines = 0;
        [self.view addSubview:teleNum];
        [teleNum release];
        //人均图片
        UIImageView *feePic = [[UIImageView alloc] initWithFrame:CGRectMake(10, 313, 20, 20)];
        feePic.image = [UIImage imageNamed:@"feePic.png"];
        feePic.layer.masksToBounds = YES;
        [self.view addSubview:feePic];
        [feePic release];
        //钱
        UILabel *fee = [[UILabel alloc] initWithFrame:CGRectMake(35, 300, self.view.frame.size.width-70, 50)];
        NSString *str = [NSString stringWithFormat:@" %ld/人", (long)[[self.mDic objectForKey:@"arg_spend"] integerValue]];
        fee.text = str;
        fee.font = [UIFont systemFontOfSize:14];
        fee.layer.borderColor = [[UIColor colorFromHexCode:@"#56abe4"] CGColor];
        fee.layer.borderWidth = 1;
        fee.layer.cornerRadius = 10;
        fee.numberOfLines = 0;
        [self.view addSubview:fee];
        [fee release];
        
        //点击返回主页
        UIImageView *backMain = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-20, 30, 40, 40)];
        backMain.image = [UIImage imageNamed:@"backToRe.png"];
        backMain.layer.masksToBounds = YES;
        backMain.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapMain = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backMain)];
        [backMain addGestureRecognizer:tapMain];
        [tapMain release];
        [self.view addSubview:backMain];
        [backMain release];
        
        //点击返回上一页
        UIImageView *back = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-20, 360, 40, 40)];
        back.image = [UIImage imageNamed:@"oneOfShopBack.png"];
        back.layer.masksToBounds = YES;
        back.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(back)];
        [back addGestureRecognizer:tap];
        [tap release];
        [self.view addSubview:back];
        [back release];
        
        [_HUD hide:YES];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"错误");
    }];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"shopDetailBackG.jpg"]];
    
    NSString *string1 = @"http://yinweiapi.paidui.com:81/jms/fetchData.do?procedureName=app_share_shop_detail&parameters=%7B%22_member_id%22%3A%220%22%2C%22_shop_id%22%3A%22";
    NSString *string2 = @"%22%2C%22_end%22%3A%2215%22%2C%22_start%22%3A%220%22%7D";
    
    NSString *str = [NSString stringWithFormat:@"%@%@%@",string1,self.num,string2];
    
    [self startAnalyze:str];
    
    self.HUD = self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
    _HUD.labelText = @"Loading";
    //_HUD.color = [UIColor clearColor];
    _HUD.mode = MBProgressHUDModeIndeterminate;
    [self.view addSubview:_HUD];
    [_HUD release];
    [_HUD show:YES];
    
    //点击返回主页
    UIImageView *backMain = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-20, 30, 40, 40)];
    backMain.image = [UIImage imageNamed:@"backToRe.png"];
    backMain.layer.masksToBounds = YES;
    backMain.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapMain = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backMain)];
    [backMain addGestureRecognizer:tapMain];
    [tapMain release];
    [self.view addSubview:backMain];
    [backMain release];
    
    //点击返回上一页
    UIImageView *back = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-20, 360, 40, 40)];
    back.image = [UIImage imageNamed:@"oneOfShopBack.png"];
    back.layer.masksToBounds = YES;
    back.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(back)];
    [back addGestureRecognizer:tap];
    [tap release];
    [self.view addSubview:back];
    [back release];
}
- (void)backMain
{
    [self.navigationController popToRootViewControllerAnimated:NO];
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
